package com.lyc.lojbackenduserservice.controller.inner;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.lyc.lojbackendmodel.model.entity.User;
import com.lyc.lojbackendserviceclient.service.UserFeignClient;
import com.lyc.lojbackenduserservice.service.UserService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;


/**
 * 该服务仅内部调用，不是给前端的
 */
@RestController
@RequestMapping("/inner")
public class UserInnerController implements UserFeignClient {

    @Resource
    private UserService userService;
    
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    
    @Resource
    private Gson gson;
    
    /**
     * 根据 id 获取用户
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public  User getById(@RequestParam("userId") Long userId){
        return userService.getById(userId);
    }

    /**
     * 根据用户昵称获取用户
     * @param userName
     * @return
     */
    @Override
    @GetMapping("get/userName")
    public User getByUserName(@RequestParam("userName") String userName){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userName", userName);
        return userService.getOne(queryWrapper);
    }


    /**
     * 根据id获取用户列表
     * @param idList
     * @return
     */
    @Override
    @GetMapping("/get/ids")
    public List<User> listByIds(@RequestParam("idList") Collection<Long> idList){
        return userService.listByIds(idList);
    }

    @Override
    @GetMapping("/get/list")
    public List<User> list(LambdaQueryWrapper<User> in) {
        return userService.list(in);
    }



}
